#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/7/7 16:38
# @Author  : CoderCharm
# @File    : curd_user.py
# @Software: PyCharm
# @Desc    :
"""

"""

from typing import Optional

from sqlalchemy.orm import Session

from core.security import get_password_hash, verify_password
from api.common.curd_base import CRUDBase
# from api.models.auth import AdminUser
from api.utils import response_code
from ..schemas import api_set_schema
from api.models.auth import ApiMsg, ApiSet, Project
import random,  re
from api.utils.captcha import captcha


class CRUDApiSet(CRUDBase[ApiSet, None, None]):

    @staticmethod
    def query_all(db: Session, project_id=int) -> ApiSet:

        # 查询结果集
        query_obj = db.query(ApiSet).filter(ApiSet.project_id == project_id).all()

        items = [{"label": obj.name,'value':obj.id} for obj in query_obj]
        # url1 = [{'url': json.loads(obj.environment_list)} for obj in query_obj]
        # print(url1)

        return {
            "items": items,
            # 'url_list': url1
        }

    # def create(self, db: Session, *, obj_in: api_set_schema.RoleLogin) -> Role:
    #     db_obj = Role(
    #         name=obj_in.name,
    #         user_id=obj_in.user_id,
    #         permission_id=obj_in.permission_id
    #     )
    #     db.add(db_obj)
    #     db.commit()
    #     db.refresh(db_obj)
    #     return db_obj


curd_api_set = CRUDApiSet(ApiSet)


